const fs = require('fs')

const readDir = (path = '') => {
    const dir = fs.readdirSync(path);
    const res = [];
    const readFile = (item) => {
        const paths = fs.readdirSync(path+'/'+item)
        const res = paths.map((it)=>{
            const obj = {
                name: it,
                path: path+'/'+item+'/'+it,
            }
            return obj
        })
        return res
    }
    dir.map((item)=>{
        res.push({
            name: item,
            paths: readFile(item)
        })
    })
    fs.writeFileSync('./resource.json',JSON.stringify(res));
    console.log('获取资源路径');
}

const readRecource = (path = '') =>{
    readDir(path + 'resource')
}

module.exports = {
    readDir,
    readRecource
}
